package com.superpai.view.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.superpai.R;
import com.superpai.domain.ShopCategory;
import com.superpai.utils.StringUtils;

/**
 * @author Devin.Hu
 * @date 2011-8-23
 * @version V1.0
 * @description 分类页adapter
 */
public class CategoryAdapter extends BaseAdapter {

	private Context mContext;
	private LayoutInflater mInflater;
	private List<ShopCategory> mList;
	private TextView category_name;
	private TextView category_num;

	public CategoryAdapter(Context context) {
		mContext = context;
		mInflater = LayoutInflater.from(mContext);
	}

	public List<ShopCategory> getmList() {
		return mList;
	}

	public void setmList(List<ShopCategory> mList) {
		this.mList = mList;
	}

	@Override
	public int getCount() {
		if (null != mList) {
			return mList.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		if (null != mList) {
			return mList.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		
		 convertView = mInflater.inflate(R.layout.category_item, null);
		 category_name = (TextView)convertView.findViewById(R.id.category_name);
		 category_num = (TextView)convertView.findViewById(R.id.category_num);
		 
		 if(mList.get(position).getParentId().equals("0")){
		     category_name.setTextColor(mContext.getResources().getColor(R.color.spikearedetail_productname_color));
			 category_name.setText(StringUtils.splitString(mList.get(position).getDesc(),18));
		 }else{
			 category_name.setTextColor(mContext.getResources().getColor(R.color.home_list_color));
			 category_name.setText("    " + StringUtils.splitString(mList.get(position).getDesc(),15));
		 }
		 //category_num.setText(String.valueOf(mList.get(position).getItemCount()));
		 
		 return convertView;
	}

}
